import 'package:get/get.dart';

class CounterController extends GetxController {
  var count = 0.obs;
  var page = 1.obs;

  @override
  void onInit() {
    super.onInit();
    print('《《 CounterController - onInit');

    // 监听一次数据的变化
    once(count, (value) => print('once: '+value.toString()));

    // 监听每次数据的变化
    ever(count, (value) => print('ever: '+value.toString()));

    // 监听多个数据的每次变化
    everAll([count, page], (value) => print('everAll: '+value.toString()));

    // 防抖 1 秒钟
    debounce(
      count, (value) {
        print('debounce: '+value.toString());
      },
      time: Duration(seconds: 1)
    );

    // 计时 1 秒钟
    interval(
      count, (value) {
        print('interval: '+value.toString());
      },
      time: Duration(seconds: 1)
    );
  }

  @override
  void onReady() {
    super.onReady();
    print('《《 CounterController - onReady');
  }

  @override
  void onClose() {
    super.onClose();
    print('《《 CounterController - onClose');
  }

  increment() => count++;
  decrement() => count--;

  loadMore() => page++;
}